# THIS FILE IS LICENSED UNDER THE MIT LICENSE AS OUTLINED IMMEDIATELY BELOW: 
#
# Permission is hereby granted, free of charge, to any person obtaining a
# copy of this software and associated documentation files (the "Software"),  
# to deal in the Software without restriction, including without limitation  
# the rights to use, copy, modify, merge, publish, distribute, sublicense,  
# and/or sell copies of the Software, and to permit persons to whom the  
# Software is furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in 
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 
# DEALINGS IN THE SOFTWARE.

# player.py
# written by: 
#     Jan Jokela <jan@devion.org>

"""
Abstracted player classes, which are eligible for use throughout the
media application. Only one 'interface' is currently provided: the
Generic one.
"""

__version__ = 0.2
__doc__ = 'Audio Player'

import drivers 

class Generic:
    """The generic interface for media playback."""

    def __init__(self, player_driver='pymedia'):
        _drivers = {
            'pygame':drivers.Pygame,
            'pymedia':drivers.Pymedia,
            'gstreamer':drivers.Gstreamer,
        }
        self.player_driver = _drivers[player_driver]()

    def play(self, media_object):
        """Starts or resumes the playback using the media_object ."""
        return self.player_driver.play(media_object)

    def pause(self):
        """Pauses the playback. If already paused, it is resumed."""
        return self.player_driver.pause()

    def stop(self):
        """Stops the playback."""
        return self.player_driver.stop()

    def seek(self, value):
        """Changes the point from where the playback should be resumed."""
        return self.player_driver.seek(value)
    
    def increment_volume(self, step):
        return self.player_driver.increment_volume()
    
    def decrement_volume(self, step):
        return self.player_driver.decrement_volume()

    def elapsed_time(self):
        """Returns a float (seconds.miliseconds) of the playback's uptime."""
        return self.player_driver.elapsed_time()
    
    def get_media(self):
        """Returns a string containing the media file uri"""
        return self.player_driver.get_media()
    
    def get_paused(self):
        """Returns True if playback is paused, False otherwise"""
        return self.player_driver.get_paused()
    
    def get_duration(self):
        """ Returns a float (seconds.miliseconds) containing the duration of the media track"""
        return self.player_driver.get_duration()
    
    def get_position(self):
        """ Returns a float (seconds.miliseconds) containing the position of the media being played"""
        return self.player_driver.get_position()
